home *** CD-ROM | disk | FTP | other *** search
/ 220 Jogos / 220 jogos.iso / classicos / genius3 / RELOJ.CPP next >
Encoding:
C/C++ Source or Header  |  2002-08-31  |  2.1 KB  |  55 lines

  1. // reloj.cpp: implementation of the reloj class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4.  
  5. #include "reloj.h"
  6.  
  7. //////////////////////////////////////////////////////////////////////
  8. // Construction/Destruction
  9. //////////////////////////////////////////////////////////////////////
  10.  
  11. reloj::reloj()
  12. {
  13.     // Check To See If A Performance Counter Is Available
  14.     // If One Is Available The Timer Frequency Will Be Updated
  15.     if (!QueryPerformanceFrequency((LARGE_INTEGER *) &frequency))
  16.     {
  17.         // No Performace Counter Available
  18.         performance_timer    = FALSE;                    // Set Performance Timer To FALSE
  19.         mm_timer_start    = timeGetTime();            // Use timeGetTime() To Get Current Time
  20.         resolution        = 1.0f/1000.0f;                // Set Our Timer Resolution To .001f
  21.         frequency            = 1000;                        // Set Our Timer Frequency To 1000
  22.         mm_timer_elapsed    = mm_timer_start;        // Set The Elapsed Time To The Current Time
  23.     }
  24.     else
  25.     {
  26.         // Performance Counter Is Available, Use It Instead Of The Multimedia Timer
  27.         // Get The Current Time And Store It In performance_timer_start
  28.         QueryPerformanceCounter((LARGE_INTEGER *) &performance_timer_start);
  29.         performance_timer            = TRUE;                // Set Performance Timer To TRUE
  30.         // Calculate The Timer Resolution Using The Timer Frequency
  31.         resolution    = (float) (((double)1.0f)/((double)frequency));
  32.         // Set The Elapsed Time To The Current Time
  33.         performance_timer_elapsed    = performance_timer_start;
  34.     }
  35. }
  36.  
  37. reloj::~reloj()
  38. {
  39.  
  40. }
  41.  
  42. float reloj::TimerGetTime()                                        // Get Time In Milliseconds
  43. {
  44.     __int64 time;                                            // time Will Hold A 64 Bit Integer
  45.  
  46.     if (performance_timer)                            // Are We Using The Performance Timer?
  47.     {
  48.         QueryPerformanceCounter((LARGE_INTEGER *) &time);    // Grab The Current Performance Time
  49.         // Return The Current Time Minus The Start Time Multiplied By The Resolution And 1000 (To Get MS)
  50.         return ( (float) ( time - performance_timer_start) * resolution)*1000.0f;
  51.     }
  52.     // Return The Current Time Minus The Start Time Multiplied By The Resolution And 1000 (To Get MS)
  53.     return( (float) ( timeGetTime() - mm_timer_start) * resolution)*1000.0f;
  54. }
  55.